package abg.core.common.web;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;

/**
 * 敏感词加载
 *
 * @author Chopper
 * @version v1.0
 * 2021-11-23 12:08
 */
@Order(9999998)
@Component
@Slf4j
public class RunInfo implements ApplicationRunner {

    @Value("${server.port}")
    private String server_port;

    //@Value("${spring.application.name}")
    private String spring_application_name;

    //@Value("${spring.cache.type}")
    private String spring_cache_type;

    //@Value("${spring.redis.host}")
    private String spring_redis_host;

    //@Value("${spring.redis.port}")
    private String spring_redis_port;

    //@Value("${logging.level.root}")
    private String logging_level_root;

    //@Value("${logging.file.path}")
    private String logging_file_path;

    //@Value("${spring.shardingsphere.datasource.default-datasource.type}")
    private String datasource_type;

    //@Value("${spring.shardingsphere.datasource.default-datasource.driverClassName}")
    private String datasource_driverClassName;

    //@Value("${spring.shardingsphere.datasource.default-datasource.username}")
    private String datasource_username;

    //@Value("${spring.shardingsphere.datasource.default-datasource.maxActive}")
    private String datasource_maxActive;

    //@Value("${spring.shardingsphere.datasource.default-datasource.initialSize}")
    private String datasource_initialSize;

    //@Value("${spring.shardingsphere.datasource.default-datasource.maxWait}")
    private String datasource_maxWait;

    //@Value("${spring.shardingsphere.datasource.default-datasource.minIdle}")
    private String datasource_minIdle;

    //@Value("${spring.shardingsphere.datasource.default-datasource.url}")
    private String datasource_url;

    //@Value("${lili.data.elasticsearch.cluster-name}")
    private String elasticsearch_cluster_name;

    //@Value("${lili.data.elasticsearch.cluster-nodes}")
    private String elasticsearch_cluster_nodes;

//    //@Value("${lili.data.logstash.server}")
//    private String logstash_server;

    //@Value("${jasypt.encryptor.password}")
    private String jasyptPassword;

    //@Value("${rocketmq.name-server}")
    private String rocketmq_name_server;

    //@Value("${rocketmq.producer.group}")
    private String rocketmq_producer_group;

    //@Value("${xxl.job.admin.addresses}")
    private String xxl_job_admin_addresses;

    //@Value("${xxl.job.executor.port}")
    private String xxl_job_executor_port;

    //@Value("${xxl.job.executor.appname}")
    private String xxl_job_executor_app_name;

    //@Value("${server.tomcat.threads.max}")
    private String tomcat_threads_max;

    //@Value("${server.tomcat.threads.min-spare}")
    private String tomcat_threads_min;


    /**
     * 输出当前服务运行相关信息
     */
    @Override
    public void run(ApplicationArguments args) {

        log.error("\n\n");
        log.error(">>>>>>>>>当前服务已成功启动");
        String _1 = MessageFormat.format("\n【服务】\n[名称] {0}\n[端口号] {1}\n[缓存类型] {2}\n[加密参数] {3}\n[最大线程] {4}\n[最小线程] {5}\n",
                spring_application_name, server_port, spring_cache_type, jasyptPassword, tomcat_threads_max, tomcat_threads_min);

        String _2 = MessageFormat.format("\n【log】\n[打印级别] {0}\n[文件位置] {1} \n",
                logging_level_root, logging_file_path);

        String _3 = MessageFormat.format("\n【redis】\n[地址] {0}:{1} \n",
                spring_redis_host, spring_redis_port);

        String _4 = MessageFormat.format("\n【数据库】\n[类型] {0}\n[驱动] {1}\n[连接字符串] {2}\n[登录账号] {3}\n" +
                        "[线程池初始化数量] {4}\n[线程池最大数量] {5}\n[线程池最小数量] {6}\n[等待时间(超时直接失败)] {7}\n",
                datasource_type, datasource_driverClassName, datasource_url, datasource_username,
                datasource_initialSize, datasource_maxActive, datasource_minIdle, datasource_maxWait);

        String _5 = MessageFormat.format("\n【elasticsearch】\n[集群] {0}\n[节点] {1}\n",
                elasticsearch_cluster_name, elasticsearch_cluster_nodes);

//        String _6 = MessageFormat.format("\n【logstash】\n[地址]{0}\n", logstash_server);

        String _7 = MessageFormat.format("\n【rocketmq】\n[server] {0}\n[group] {1}\n",
                rocketmq_name_server, rocketmq_producer_group);

        String _8 = MessageFormat.format("\n【xxl-job】\n[Admin地址] {0}\n[端口号] {1}\n[名称] {2}\n\n",
                xxl_job_admin_addresses, xxl_job_executor_port, xxl_job_executor_app_name);

        String msg = _1 + _2 + _3 + _4 + _5 + _7 + _8;
        log.error(msg);
    }

}
